#include "stdafx.h"
#include "../../GameCore/CGame.h"

#define ABOUT_BUTTON_NUMBER	1
#define ABOUT_BUTTON_CLOSE	0
Button _arrButton[ABOUT_BUTTON_NUMBER];

#define _DEC_NUMBER_BUTTON		(ABOUT_BUTTON_NUMBER)
#define _DEC_ARR_BUTTONN		(_arrButton)
#define _DEC_ANIM_BUTTON_BEGIN	0


void CGame::UpdateAbout()
{
	if(_GameSubState==k_INIT)
	{
		for(int i=0;i<_DEC_NUMBER_BUTTON;i++)
		{
			//printf("\nabout===");
			_DEC_ARR_BUTTONN[i].Init(BUTTON_STATE_NORMAL, 0, 0,A_HVCENTER);
			_DEC_ARR_BUTTONN[i].SetAnim(GET_SPRITE(GFX_HUD_ABOUT),_DEC_ANIM_BUTTON_BEGIN+i*4);
		}
		SetSubState(k_LOOP);
	}
	else if(_GameSubState==k_LOOP)
	{
		if(TouchAbout())
		{}
	}
	else if(_GameSubState==k_DESTROY)
	{
		SetGameState(_GameStateNew, false);
	}
}
bool CGame:: TouchAbout()
{
	bool ret=false;
	bool pressed=false;
	int index=-1;
	for(int i=0;i<_DEC_NUMBER_BUTTON;i++)
	{
		if(_DEC_ARR_BUTTONN[i]._state==BUTTON_STATE_ACTIVE)
		{
			index=i;
			ret=true;
			break;
		}
	}
	if(ret)
	{
		if(_DEC_ARR_BUTTONN[index].NeedAction())
		{
			switch(index)
			{
			case ABOUT_BUTTON_CLOSE:
				//SetGameState( k_GS_MAIN_MENU, false);
				break;
			}
		}
		for(int i=0;i<_DEC_NUMBER_BUTTON;i++)
		{
			_DEC_ARR_BUTTONN[i].SetState(BUTTON_STATE_NORMAL);
			CGame::_this->ClearTouchesEnd();
		}
		return true;
	}
	else
	{
		for(int i=0;i<_DEC_NUMBER_BUTTON;i++)
		{
			_DEC_ARR_BUTTONN[i].SetState(BUTTON_STATE_NORMAL);
			
		}
	}
	for(int i=CGame::_this->_num_touches-1;i>=0;i--)
	{
		if(CGame::_this->_touches[i]->_flag && !pressed)
		{
			for(int touch=0;touch<_DEC_NUMBER_BUTTON;touch++)
			{
				int x=_DEC_ARR_BUTTONN[touch].TZ_GetX();
				int y=_DEC_ARR_BUTTONN[touch].TZ_GetY();
				int w=_DEC_ARR_BUTTONN[touch].TZ_GetWidth();
				int h=_DEC_ARR_BUTTONN[touch].TZ_GetHeight();
				if(CHECK_POINT_IN_RECT(CGame::_this->_touches[i]->x,CGame::_this->_touches[i]->y,x,y,w,h))
				{
					if(CGame::_this->_touches[i]->_state==TOUCH_DOWN||CGame::_this->_touches[i]->_state==TOUCH_DRAG)
					{
						_DEC_ARR_BUTTONN[touch].SetState(BUTTON_STATE_SELECT);
						pressed=true;
						break;
					}
					else if(CGame::_this->_touches[i]->_state==TOUCH_UP)
					{
						_DEC_ARR_BUTTONN[touch].SetState(BUTTON_STATE_ACTIVE);
						CGame::_this->_touches[i]->_flag=false;
						pressed=true;
						CGame::_this->ClearTouchesEnd();
						break;
					}
				}
			}
		}
	}
	if(pressed==false)
	{
		Button::ResetPlaySound();
		return false;
	}
	else
		return true;

	return false;

}
void CGame::RenderAbout()
{
	if(_GameSubState==k_LOOP)
	{
		GET_SPRITE(GFX_HUD_BODER)->DrawFrame(GL(),12,0,0);
		GET_SPRITE(GFX_HUD_BODER)->DrawFrame(GL(),13,0,0);

		GET_SPRITE(GFX_HUD_ABOUT)->DrawFrame(GL(),1,0,0);

		for(int i=0;i<_DEC_NUMBER_BUTTON;i++)
		{
			_DEC_ARR_BUTTONN[i].Update();
			_DEC_ARR_BUTTONN[i].Render(GL());
		}
	}
}